package cn.le.netty.serious;

import io.netty.handler.codec.marshalling.*;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;

public class MarshallingCodeFactory {

    public static MarshallingDecoder buildMarshllingDecoder(){
       // System.out.println("解码");
        //获取jdk的序列号
        try {
            MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
            MarshallingConfiguration configuration = new MarshallingConfiguration();
            configuration.setVersion(5);
            UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory,configuration);
            int maxSize = 1024 ;//<< 2;//设置单个最大长度
            MarshallingDecoder decoder = new MarshallingDecoder(provider,maxSize);
            return decoder;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;

    }

    public static MarshallingEncoder builMarshallingEncoder(){
        //System.out.println("编码");
        try {
            MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
            MarshallingConfiguration configuration = new MarshallingConfiguration();
            configuration.setVersion(5);
            MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory,configuration);
            MarshallingEncoder encoder = new MarshallingEncoder(provider);
            return encoder;
        }catch (Exception e){
            e.printStackTrace();
        }
       return null;
    }

}
